-- Cave 1


function autoexec()
   


return
refresh()
end


function postexec()
  if (get_progress(P_VAULT) == 1) then
    set_btile("vault", 251)
  end
  
if (get_progress(P_QUEST1) == 5) then
    set_ent_active(0,0)
    set_ent_active(1,0)
  elseif (get_progress(P_QUEST1) == 6) or (get_progress(P_QUEST1) == 7) then
    set_ent_active(0,0)
    set_ent_active(1,0)
    LOC_open_chamber_empty()
  end

return
end


function zone_handler(zn)
  if (zn == 1) then
    change_map("land","cave1_exit");
    
  elseif (zn == 2) then
    chest(6, 0, 7)
    refresh()
    thought(HERO1,"I think someone got here before me.");
    
  elseif (zn == 3) then
    warp("stairs_dn1",8)
    
  elseif (zn == 4) then
    warp("stairs_up2",8)
      
  elseif (zn == 5) then
    thought(HERO1,"Hmm a strange statue.");
        
  elseif (zn == 6) then
    thought(HERO1,"This could be a tomb...");
          
  elseif (zn == 7) then
    bubble(HERO1,"What is that?") ;
             
  elseif (zn == 8) then
    thought(HERO1,"Just an empty pot.");
                 
  elseif (zn == 9) then
    chest(7, I_NLEAF, 1)
      refresh()
    
    
  elseif (zn == 10) then
    thought(HERO1,"This one is empty.");    
        
  elseif (zn == 11) then
    chest(8, I_MHERB, 1)
    refresh()

    
  elseif (zn == 12) then
    thought(HERO1,"Locked.");    
  
  elseif (zn == 13) then
  if (get_progress(P_VAULT) == 0) then
    combat(1)
  else
  end
   
  elseif (zn == 14) then
  if (get_progress(P_VAULT) == 0) then
    combat(1)
  else
  end
          
 elseif (zn == 15) then
   chest(9, I_NLEAF, 1)           
  
 elseif (zn == 16) then
   if (get_progress(P_QUEST1) == 2) then
   bubble(HERO1,"What a long and pointless hallway.");
   bubble(HERO1,"Wait a minute I see something on the wall, a little indent in that brick.");
   bubble(HERO1,"I am going to press it and see what happens.");
   bubble(HERO2,"I don't know if thats a good idea...");
   wait_for_entity(HERO1, HERO1)
   msg("$0 reaches down and presses the brick.",255,0)
   sfx(25)
   set_progress(P_VAULT,1)
   set_btile("vault", 251)
   set_progress(P_QUEST1,3)
   refresh()
   else
   bubble(HERO1,"I already activated the switch.");
end

 elseif (zn == 17) then
   warp("vault_enter",2)

 elseif (zn == 18) then
   if (get_progress(P_QUEST1) == 5) or (get_progress(P_QUEST1) == 6) or (get_progress(P_QUEST1) == 7) then
     warp("vault_exit",8)
   else
     msg("The Vault guardians won't let you escape",255,0)
   end

 elseif (zn == 19) then
   chest(10, 0, 63)
      refresh()

 elseif (zn == 20) then
   bubble(HERO1, "Ugh There is nothing in there that I want.");

 elseif (zn == 21) then
   chest(11, 0, 95)

 elseif (zn == 23) then
   if (get_progress(P_QUEST1) == 3) then
    set_progress(P_QUEST1,6)
    LOC_open_chamber()
    end
 
 elseif (zn == 24) then
   bubble(HERO1,"Whats this on the ground?")
   set_zone("chamberf",25)   
   sfx(5)
   msg("Key piece procurred!",255,0) 
   set_btile("chamberf", 240)
   bubble(HERO1,"Wait a minute its only half a key...");
   bubble(HERO2,"Well... I think the rebellion will know what to do. We need to report back to them. We can get to their headquarters in the Capital. Its the town northeast from here. We should talk to the owner of the inn there.");
   set_progress(P_QUEST1,7)

 elseif (zn == 25) then
--   bubble(HERO1,"I already took the key.")
  
  elseif (zn == 26) then
   if (get_progress(P_VAULT) == 0) then
    combat(1)
   else
   end

           end



function entity_handler(en)
  if (en == 0) then
    LOC_talk_guard2(en)
  
  elseif (en == 1) then
    LOC_talk_guard1(en)
    
    

--     
    
  end

  end


function LOC_talk_guard1(en)
  bubble(en,"Who dares open the Vault of the Brotherhood!");
  bubble(HERO1,"That would be me, $0 the Fierce.");
  bubble(en,"You will die for disturbing the vault!");
  drawmap()
  screen_dump()
  set_run(0)
  combat(11)
  set_run(1)
  if (get_alldead() == 1) then
    return
  end
  set_progress(P_QUEST, 4)
  refresh()
  set_ent_active(1, 0)
  drawmap()
  screen_dump()
  
end


function LOC_talk_guard2(en)
  bubble(en,"There is no need for discussion.");
  drawmap()
  screen_dump()
  set_run(0)
  combat(11)
  set_run(1)
  if (get_alldead() == 1) then
    return
  end
  set_progress(P_QUEST, 5)
  refresh()
  set_ent_active(0, 0)
  drawmap()
  screen_dump()
end
end

function LOC_open_chamber() --open chamber where key is hidden.
  bubble(HERO1,"Ah hah there is a switch here.");
  msg("$0 reaches down and presses the switch.",255,0)
  sfx(16)
  set_progress(P_TOMB,1)  
  set_btile("chamberb", 240)
  set_btile("chamberf", 380)
  set_zone("chamberf", 24)
  set_obs("chamberf",0)
  set_obs("chamberb",0)


  set_ftile("tombf", 235)
  set_ftile("tombb", 234)
  set_zone("tombf", 6)
  set_obs("tombf", 1)
  set_obs("tombb", 1)
  bubble(HERO1,"I am pretty sure something big just happened.")
  bubble(HERO2,"Yeah lets go check it out.")
  refresh()
end


function LOC_open_chamber_empty() --open chamber door when you return.
  
  set_progress(P_TOMB,1)  
  set_btile("chamberb", 240)
  set_btile("chamberf", 240)
  set_zone("chamberf", 25)
  set_obs("chamberf",0)
  set_obs("chamberb",0)


  set_mtile("tombf", 235)
  set_mtile("tombb", 234)
  set_zone("tombf", 6)
  set_obs("tombf", 1)
  set_obs("tombb", 1)
  refresh()
end


function refresh()
 if (get_treasure(7) == 1) then
    set_ftile("chest1", 256)
    set_zone("chest1", 10)
  end    
    
  if (get_treasure(8) == 1) then
    set_ftile("chest2", 256)
    set_zone("chest2", 10)
  end  

  if (get_treasure(10) == 1) then
    set_ftile("chest3", 256)
    set_zone("chest3", 10)
  end  

  if (get_progress(P_QUEST1) == 3) then
    set_ftile("vault", 251)
    set_obs("vault",0)
    set_zone("vault",17)
--     
  elseif (get_progress(P_QUEST1) == 4) then
    set_ent_active(1, 0)
  
  elseif (get_progress(P_QUEST1) == 5) then
    set_ent_active(0, 0)
  
  else
--     set_ent_script("K")
  
  end 
       

  return
end

